//
//  WebViewController.m
//  YRSideViewController
//
//  Created by xiabin on 15/1/24.
//  Copyright (c) 2015年 YueRuo. All rights reserved.
//

#import "WebViewController.h"

@interface WebViewController ()
@property (strong, nonatomic) NSString *weburl;
@property (strong, nonatomic) NSString *navTitle;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityView;
@end

@implementation WebViewController

#pragma mark life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.webpage.delegate = self;
    [self.view bringSubviewToFront:self.activityView];
    NSURL *url =[NSURL URLWithString:_weburl];
    NSURLRequest *request =[NSURLRequest requestWithURL:url];
    [_webpage loadRequest:request];
    [self initNavStyle];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//开始加载数据
- (void)webViewDidStartLoad:(UIWebView *)webView {
    [self.activityView startAnimating];
    [self.activityView setHidden:NO];
}

//数据加载完
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [self.activityView stopAnimating];
    [self.activityView setHidden:YES];
}

-(void)viewWillAppear:(BOOL)animated {
    [MobClick beginLogPageView:[NSString stringWithFormat:@"%@WebPage", self.navTitle]];
}

-(void)viewWillDisappear:(BOOL)animated {
    [MobClick endLogPageView:[NSString stringWithFormat:@"%@WebPage", self.navTitle]];
}

- (instancetype)initWithurl:(NSString *)url andTitle: (NSString*) title {
    self = [super init];
    if (self) {
        self.weburl = url;
        self.navTitle = title;
    }
    return self;
}

- (instancetype)initWithurl:(NSString *)url
{
    self = [super init];
    if (self) {
        self.weburl = url;
    }
    return self;
}

#pragma mark UI Event
- (void) popBack {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark private methods
-(void) initNavStyle {
    UIButton* cancelBtn = [Utils NavButtonStyleNormalBLeft:YES NormalImg:@"back" AndHightLight:@"back_highlight"];
    [cancelBtn addTarget:self action:@selector(popBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:cancelBtn];
    self.navigationItem.title = self.navTitle;
}

@end
